<template>
  <div class="mapConter">
    <div class="dragSearch">
      <div class="searchStyleP">
        <div class="searchStyle">
          <el-input
            placeholder="输入地址"
            @input="handleInsertPointClick"
            v-model="input4"
            @focus="handleChangeIds"
          >
            <i slot="prefix" class="el-input__icon el-icon-search"></i>
          </el-input>
          <el-button type="warning" class="searchBtn" @click="handleSearchData"
            >搜索</el-button
          >
        </div>
        <div class="searchStyleAbsolute" v-show="changeId">
          <!-- handlelistSearch -->
          <div
            class="searchStyleAbsolute-item pianqu1"
            @click="handleSearchData(item)"
            v-for="(item, index1) in [...resultsApiList, ...resultsAsList]"
            :key="index1"
          >
            <img class="w18" src="@/assets/map/sous.jpg" alt="" srcset="" />
            {{ item.title }} <span v-if="item.geom84" class="pianqu">片区</span>
          </div>
        </div>
      </div>

      <div class="slideStyle">
        <div class="huakuai">
          <div class="huakuai-left">
            <el-checkbox @change="handlePointInit" v-model="isChecked"
              >半径范围</el-checkbox
            >
          </div>
          <div class="huakuai-right">
            <div class="huakuai-right-">
              <!-- <el-slider
              v-model="getKM"
              :min="0.5"
              :max="3"
              :step="1"
              @input="getTime"
            ></el-slider> -->
              <el-slider
                v-model="getKM"
                :min="0"
                :max="3"
                @change="getTime"
              ></el-slider>
            </div>
            <!--  :style=" index==1?'margin-left:-60px':''" -->
            <div class="huakuai-right-bottom">
              <div
                v-for="(item, index) in list"
                :key="index"
                class="lab"
                @click="setKMMap(item)"
                :class="item.id === TabId ? 'activeLab' : ''"
              >
                {{ item.lable }}km
              </div>
            </div>
          </div>
        </div>
      </div>
    </div>
    <!-- 2111111111111111111111 -->
    <div class="leftButtonStyle">
      <img :src="jia" @click="zoomIn" alt="" class="jia" />
      <img :src="jian" @click="zoomOut" alt="" class="jian" />
    </div>
    <baidu-map
      id="baidumap"
      :center="mPoint2"
      :zoom="10"
      :scroll-wheel-zoom="true"
    >
      <!-- https://blog.csdn.net/m0_74094484/article/details/132684690 弹窗 -->

      <!-- <div v-for="(item, index) in mapPointsList" :key="index">
        <bm-marker
          :averageCenter="true"
          :position="{ lng: item.center.lng, lat: item.center.lat }"
          :key="index"
        >
          <bm-label
            :content="item.address"
            :labelStyle="labelStyle"
            :offset="{ width: 0, height: -10 }"
          />
        </bm-marker>
      </div> -->
    </baidu-map>

    <div class="rightMove" @click="handleRightMove"><rightMove /></div>
    <el-drawer
      v-drawerDrag
      class="drawers"
      :modal="false"
      :visible.sync="$store.state.map.drawer"
      :direction="direction"
      :with-header="false"
      :size="drawerWidth"
    >
      <div class="tabsPadding">
        <el-tabs stretch v-model="activeName" @tab-click="handleClick">
          <el-tab-pane :label="labelQY" name="first">
            <div slot="label">
              <span class="key" :class="tabName == 'first' ? 'active' : ''">{{
                labelQY
              }}</span>
              <span class="totalLYLable">{{ totalQY }}</span>
            </div>
            <nearbyEnterprises
              :key="QYINDEX"
              @setPageNumQY="setPageNumQY"
              :totalQY="totalQY"
              :enterpriselist="enterpriselist"
              :pageNumberQY="pageNumberQY"
            />
          </el-tab-pane>

          <!-- <el-tab-pane :label="labelHD" name="hd">
            <div slot="label">
              <span class="key" :class="tabName == 'hd' ? 'active' : ''">{{
                labelHD
              }}</span>
            </div>
            <el-button type="text">暂未开放</el-button>
         </el-tab-pane>

          <el-tab-pane :label="labelXQ" name="xq">
            <div slot="label">
              <span class="key" :class="tabName == 'xq' ? 'active' : ''">{{
                labelXQ
              }}</span>
            </div>
            <el-button type="text">暂未开放</el-button>
          </el-tab-pane>
          <el-tab-pane :label="labelCP" name="kf">
            <div slot="label">
              <span class="key" :class="tabName == 'kf' ? 'active' : ''">{{
                labelCP
              }}</span>
            </div>
            <el-button type="text">暂未开放</el-button>
          </el-tab-pane> -->
          <el-tab-pane :label="labelLY" name="second">
            <div slot="label">
              <span class="key" :class="tabName == 'second' ? 'active' : ''">{{
                labelLY
              }}</span>
              <span class="totalLYLable">{{ totalLY }}</span>
            </div>
            <currentTitle
              :address="input4"
              :distance="getKM"
              :basetaglist="basetaglist"
              :key="KMKET"
            />

            <tableComponentsLy
              :loadingLY="loadingLY"
              :total="totalLY"
              :enterpriselist="[...inPointList, ...enterpriselistLY2]"
              @setPageNum="setPageNum"
            />
          </el-tab-pane>
        </el-tabs>
      </div>
    </el-drawer>
  </div>
</template>

<script>
import { basetagapi } from "@/api/enterprise/index";
import dragMove from "./svg/dragMove.vue";
import dragMoveTo from "./svg/dragMoveTo.vue";
import rowSearch from "@/components/Map/rowSearch.vue";
import nearbyEnterprises from "@/components/Map/nearbyEnterprises.vue";
import drag from "@/components/Map/dragButton.vue";
import rightMove from "@/components/Map/svg/rightMove.vue";
import currentTitle from "@/components/Map/currentTitle.vue";
import currentTitleYuLou from "@/components/Map/currentTitleYuLou.vue";
import tableComponents from "@/components/Map/tableComponents.vue";
import tableComponentsLy from "@/components/Map/tableComponentsLy.vue";
import { mapActions } from "vuex";
import { BmMarker, BmLabel, BMapGL, BMapLib } from "vue-baidu-map";
import {
  ly_shp_geo_polygon_company_list,
  company_base_listTab,
  ds_ly_swly_list,
} from "@/api/map/index";
import gcoord from "gcoord";
import Vue from "vue";
import C10yUtil from "@/utils/c10y-util";

export default {
  components: {
    nearbyEnterprises,
    drag,
    rightMove,
    currentTitle,
    currentTitleYuLou,
    tableComponents,
    tableComponentsLy,
    rowSearch,
    BmMarker,
    BmLabel,
    BMapGL,
    BMapLib,
    dragMove,
    dragMoveTo,
  },
  data() {
    return {
      successLY: 0,
      inPointList: [],
      sliderValue: [0, 3],
      marks: {
        0: 0.5,
        1: 1,
        2: 2,
        3: 3,
      },
      basetaglist: [],
      TabId: 0,
      list: [
        {
          lable: 0.5,
          id: 0,
          scale: 2,
        },
        {
          lable: 1,
          id: 1,
          scale: 3,
        },
        {
          lable: 2,
          id: 2,
          scale: 4,
        },
        {
          lable: 3,
          id: 3,
          scale: 5,
        },
      ],
      input4: "",
      KMKET: 0,
      tabName: "",
      jia: require("@/assets/map/fangda.png"),
      jian: require("@/assets/map/suoxiao.png"),
      pageNumberQY: 1, //当前页
      pageNumber: 1, //当前页
      total: 0, //企业总数
      enterpriselist: [], //企业列表
      ChildSearchsV: {}, //企业的所有参数
      labelQY: "附近企业",
      labelLY: "片区",
      labelHD: "附件活动",
      labelXQ: "企业需求",
      labelCP: "企业产品",
      enterpriselistLY: [],
      enterpriselistLY2: [],
      totalLY: 0,
      totalQY: 0,
      loadingLY: false, //楼宇loading
      drawer: false,
      direction: "rtl",
      activeName: "first",
      drawerWidth: "860px",
      address: "广东省广州市黄埔区",
      addressSearch: "成都市财富国际",
      distance: 0,
      getKM: 0.5,
      map: null,
      mPoint: {
        lng: 113.43018920877583,
        lat: 23.1695923058413,
      },
      mPoint2: {
        lng: 113.43018920877583,
        lat: 23.1695923058413,
      },
      isChecked: false, //是否选中的状态
      searchData: "", //搜索的数据
      mapPointsList: [],
      centerList: [], //中心点坐标，请求楼宇数据
      labelStyle: {
        color: "red",
        fontSize: "14px",
        border: "none",
        background: "none",
        fontWeight: "600",
      },
      canPaintPoly: 0,
      circleListLngLat: [],
      QYINDEX: 0,
      resultsAsList: [],
      resultsApiList: [],
      changeId: false,
      search: false,
      lyId: "",
      creditNo: "",
    };
  },
  created() {
    let _this = this;
    setTimeout(() => {
      _this.createMap();
    }, 500);
  },

  methods: {
    ...mapActions("map", ["handledrawer"]),

    createMap() {
      let _this = this;
      // 百度地图API功能
      _this.map = new BMap.Map("baidumap");

      // var local = new BMap.LocalSearch(this.map, {
      //   // 自动打点
      //   // renderOptions: { map: _this.map, autoViewport: false },
      // });

      // if (_this.input4) {
      //   local.search(_this.input4);
      //   local.setSearchCompleteCallback(function (results) {
      //     _this.resultsAsList = results?.as.map((flag) => {
      //       return {
      //         name: flag.address,
      //         polygoncenterdata: flag.point.lng + "," + flag.point.lat,
      //         id: flag.id,
      //         ...flag,
      //       };
      //     });
      //     console.log("搜索出来的位置", results?.as);
      //   });
      // } else {
      //   console.log("初始化坐标点", _this.mPoint);

      // }
      _this.mPoint = new BMap.Point(_this.mPoint?.lng, _this.mPoint?.lat);
      _this.map.enableScrollWheelZoom();
      _this.map.centerAndZoom(_this.mPoint, 16);
      // local.searchNearby(_this.input4, _this.mPoint, _this.getKM * 1000);
    },
    handleRightMove() {
      this.$store.dispatch("map/handledrawer");
    },

    handleClick(tab, event) {
      this.tabName = tab.name;
      console.log("000-----", tab);
    },

    // 设置距离
    setKM(item) {
      let _this = this;
      _this.TabId = item;
      console.log("itemitemitemitemitemitemitemitemitem", item);
      _this.getKM = _this.marks[item.id];
      console.log("wwwwwwwwwwwwwwwwwwwwwwwww", _this.marks);
      _this.successLY = 0;

      _this.handleChecked(true);
    },
    // 没有列表，需要搜索列表
    handleSearchData(item) {
      let _this = this;
      _this.search = true;
      _this.changeId = false;
      _this.inPointList = [];
      _this.input4 = item.title || _this.input4;
      _this.lyId =item.id ?? 44908
      console.log("000000000000000", item.id);
      // 将地址解析成坐标
      var myGeo = new BMap.Geocoder();
      myGeo.getPoint(
        _this.input4,
        function (point) {
          if (point) {
            // _this.mPoint = _this.convertGoogleToBaidu(point.lat, point.lng);
            _this.mPoint = {
              lng: point.lng,
              lat: point.lat,
            };
            console.log("2222222222222222222222222", _this.mPoint);
            let items = {
              title: _this.input4,
              point: {
                lng: point.lng,
                lat: point.lat,
              },
              center: {
                lng: point.lng,
                lat: point.lat,
              },
              id: "",
              comCount: "",
              geom84: "",
            };
            _this.handlelistSearch(items);
          } else {
            // 地址没有解析到坐标
            alert("无法获取地址的坐标，请检查地址是否正确。");
          }
        }.bind(this),
        "广州市"
      );
    },
    // 搜索后选中的点位
    // 已经有列表了
    handlelistSearch(items) {
      let item = {
        item: items,
        searchData: items.title,
      };

      let _this = this;
      _this.successLY = 0;
      // _this.map.clearOverlays();
      _this.changeId = false;
      _this.isChecked = true;
      // _this.lyId = item.item.id;
      // _this.creditNo =item.item.creditNo
      _this.input4 = items.title;
      // _this.handleds_ly_swly_list(item.searchData);
      _this.KMKET++;
      console.log("点击地址时获取的金纬度", items);
      // _this.inPointList = [];
      // let slists = items?.geom84?.replace("POLYGON((", "")?.replace("))", "");

      // _this.inPointList.push({
      //   polygoncenterdata: item.item.point.lng + "," + item.item.point.lat,
      //   name: items.title,
      //   coordinates: slists ?? [],
      //   id: item?.item?.id,
      //   comCount: items?.comCount,
      //   geom84: items?.geom84,
      //   center: {
      //     lat: item.item.point.lat,
      //     lng: item.item.point.lng,
      //   },
      // });
      // 选中的点为中心点
      _this.mPoint = {
        lat: items.point.lat,
        lng: items.point.lng,
      };

      _this.handleChecked(true);
      // _this.setMarker();
      // _this.miaobian();
    },
    handlePointInit(v) {
      let _this = this;
      if (v == false) {
        _this.enterpriselistLY2=[]
       let  mapPointsLists =[];
        [..._this.mapPointsList,..._this.resultsAsList ].forEach(item => {

          if(item?.address ===_this.input4 ||item?.name ==_this.input4 ){
            console.log('--------_this.address',item?.address +'====='+_this.input4);
              mapPointsLists.push(item);
          }


            })
        //     let mapPointsListsArr =[]
        //     for (var i = 0; i < mapPointsLists.length; i++) {

				// if(mapPointsLists[i].name.indexOf(_this.input4) >-1 || _this.input4 ){
        //   mapPointsListsArr.push(mapPointsLists[i]);
        //   return
        // }
      // }
      console.log('--------_this.input4',_this.input4);
            _this.enterpriselistLY2=[mapPointsLists[0]];
            _this.mapPointsList  =[mapPointsLists[0]];
            console.log('---1------',_this.enterpriselistLY2);
            console.log('---2------',_this.mapPointsList);

            // 隐藏多余的点坐标
            setTimeout(()=>{

                    _this.map.clearOverlays();
                    _this.setMarker();
                    _this.miaobian();
                    let centerNum =  (_this.getKM == 0 || _this.getKM == 1) ? 2000 : _this.getKM * 2000;
            var circle = new BMap.Circle( {
              lat:   _this.enterpriselistLY2[0].center.lat,
              lng:   _this.enterpriselistLY2[0].center.lng
            }, centerNum, {
              fillColor: "#6197FF",
              strokeWeight: 1,
              fillOpacity: 0.12,
              strokeOpacity: 1,
              strokeColor: "blue",
            });
            _this.map.addOverlay(circle);
            },500)

        _this.successLY = 1;
      } else {
        _this.successLY = 0;
        let centerNum = (_this.getKM == 0 || _this.getKM == 1) ? 2000 : _this.getKM * 1000;

        var circle = new BMap.Circle(_this?.mPoint, centerNum, {
          fillColor: "#6197FF",
          strokeWeight: 1,
          fillOpacity: 0.12,
          strokeOpacity: 1,
          strokeColor: "blue",
        });
        _this.map.addOverlay(circle);
      }
    },
    // 设置是否有圈
    handleChecked(v) {
      let _this = this;
      console.log("==是否是选中转态1======>", v);
      console.log("==是否是选中转态2======>", _this.getKM);
      console.log("==是否是选中转态3======>", _this?.mPoint);
      console.log("==是否是选中转态4======>", _this?.successLY);

      if (v == true) {
        if(typeof _this.map.clearOverlays =='function') {
          _this.map.clearOverlays();
        }


        let centerNum =  (_this.getKM == 0 || _this.getKM == 1) ? 2000 : _this.getKM * 2000;

        var circle = new BMap.Circle(_this?.mPoint, centerNum, {
          fillColor: "#6197FF",
          strokeWeight: 1,
          fillOpacity: 0.12,
          strokeOpacity: 1,
          strokeColor: "blue",
        });

        // window.setTimeout(() => {
        //   _this.map?.panTo(
        //     new BMap.Point(_this?.mPoint?.lng, _this?.mPoint?.lat),
        //     11
        //   );
        // }, 1000);
        _this.map.addOverlay(circle);

        _this.circleListLngLat = circle?.ha;
        console.log('-----边界--------------', _this.circleListLngLat )
        if (circle?.ha?.length > 0) {
          _this.setPoints(_this.circleListLngLat);
        }
      } else {
        console.log("中心点--------------", _this.mPoint);
        // _this.enterpriselistLY2=[]
        _this.map.clearOverlays();
        _this.setMarker();
        _this.miaobian();
        _this.successLY = 0;
      }
    },
    // 获取中心点坐标
    setPoints(list) {
      let polygon = "";
      // let coord = 1;
      let lists = list.map((item) => [item.lng, item.lat]);
      lists?.forEach((v, i) => {
        let unit = i != lists.length - 1 ? ", " : "";
        polygon +=
          gcoord.transform(v, gcoord.BD09, gcoord.WGS84).join(" ") + unit;
      });

      polygon = "POLYGON ((" + polygon + "))";
      this.polygonString = polygon;
      console.log("----搜索楼宇和企业-------->>>", list);
      if (list.length > 0 && this.successLY == 0) {
        this.handlely_shp_geo_polygon_company_list();
        this.handleChildSearchs();
      }
    },
    handleInsertPointClick() {
      let _this = this;
      var local = new BMap.LocalSearch(this.map, {
        // 自动打点
        // renderOptions: { map: _this.map, autoViewport: false },
      });
      if (_this.input4) {
        // _this.map.addControl(
        //   new BMap.NavigationControl({ type: BMAP_NAVIGATION_CONTROL_SMALL })
        // );
        local.search(_this.input4);
        local.setSearchCompleteCallback(function (results) {
          // _this.mPoint = results?.getPoi(0)?.point;
          _this.resultsAsList = results?.as.map((flag) => {
            return {
              name: flag.address,
              polygoncenterdata: flag.point.lng + "," + flag.point.lat,
              id: flag.id,
              ...flag,
            };
          });
          console.log("搜索出来的位置------------------", results);
        });
      }
      _this.handleds_ly_swly_list(_this.input4);
    },

    handler({ BMap, map }) {
      let _this = this;
      _this.map = BMap;
    },
    setMarker() {
      let _this = this;
      // ..._this.inPointList,
      // console.log("--------1-------------", [..._this.enterpriselistLY2]);
      // console.log("---------2-------------", _this.enterpriselistLY);
      // console.log("---------3-------------", _this.enterpriselistLY2);
      //
      // ..._this.resultsAsList,
      //   ..._this.enterpriselistLY,
      //     ..._this.inPointList,
      _this.mapPointsList = _this.enterpriselistLY2?.map((item, index) => {
        let slist = item?.geom84?.replace("POLYGON((", "")?.replace("))", "");

        return {
          center: {
            // lng: item?.polygoncenterdata?.split(",")[0],
            // lat: item?.polygoncenterdata?.split(",")[1],
		      	lng: item?.center?.lng   ||  item?.centerPoint[0],
			       lat: item?.center?.lat || item?.centerPoint[1],
          },
          coordinates: slist ?? [],
          address: item?.name || item?.address,
          id: item.id,
          comCount: item.comCount,
		  polygonFormat:item.polygonFormat
        };
      });

      const mapIcon = new BMap.Icon(
        require("@/assets/map/mapcenter.png"),
        new BMap.Size(40, 52)
      );
      _this.mapPointsList?.forEach((items) => {
        let content = `<div style="position:relative;">
        <div class="bubble">${items.address}(${items.comCount || 0}家)</div>
        <div  style="position: absolute;
        bottom: 6;
        left: 40%;  transform: rotate(180deg);
        border-color: transparent transparent transparent #0071DF;
        transform: translateY(50%);"><img style="width: 20px;height: 15px;" src="${require("@/assets/map/xia.png")}"/></div>
        </div>`;
        // let point = new BMap.Point(items.center.lng, items.center.lat);
        // let marker = new BMap.Marker(point, { icon: mapIcon });
        // _this.map.addOverlay(marker)
        _this.addMarker(content, items.center, items.id, items.address);
      });
      // console.log("pointsList ", _this.mapPointsList);
    },
    addMarker(str, point, id, address) {
      // console.log("搜索接口返回数据==2---------->", str, point, id, address);

      let _this = this;
      let label = new BMap.Label(str, {
        position: new BMap.Point(point.lng, point.lat),
        offset: new BMap.Size(0, 0), //设置文本偏移量
      });
      label.setStyle({
        fontWeight: 500,
        fontSize: "12px",
        color: "#fff",
        backgroundColor: "#0071DF",
        borderRadius: "53px",
        border: "2px solid #fff",
        padding: "10px 20px",
      });
      this.map.addOverlay(label); // 为标注添加文本标注
      label.addEventListener("click", function (e) {
        _this.$router.push({
          path: "/bus-neighbors",
          query: { id, name: address },
        });
      });
    },
    // 中心点边界坐标
    flattenArray(arr) {
      return arr
        .reduce(
          (acc, val) =>
            Array.isArray(val)
              ? acc.concat(this.flattenArray(val))
              : acc.concat(val),
          []
        )
        .join(",");
    },
    // 描边..._this.inPointList,
    miaobian() {
      let _this = this;
      let miaolist = [..._this.mapPointsList];
      console.log("========描边数据=========>>>>>>>", miaolist);
      miaolist?.forEach((item) => {
        // if (item.coordinates.length == 0) return;
		     _this.addDistrict(item.polygonFormat, item.center);
      });
    },
    addDistrict(data) {
      var points = [];
      // let Arr = data && data.split(",");
	  let Arr = data;
      Arr?.forEach((item) => {
        // let item1 = item.split(" ");
        // points.push(new BMap.Point(item1[0], item1[1]));
		points.push(new BMap.Point(item[0], item[1]));
      });

      let _this = this;

      // 创建多边形
      var polygon = new BMap.Polygon(points, {
        strokeColor: "#0071df",
        strokeWeight: 2,
        strokeOpacity: 0.5,
        fillColor: "#3A2B5D",
        fillOpacity: 0.3,
        strokeStyle: "dashed",
      });
      // 将多边形添加到地图中
      _this.map.addOverlay(polygon);
      // 设置视图中心和缩放级别
      // _this.map.centerAndZoom(new BMap.Point(center.lng, center.lat), 15);
    },

    setPageNumQY(val) {
      this.pageNumberQY = val;
      console.log("099999999999999999999999", val);
      setTimeout(() => {
        this.handleChildSearchs();
      }, 1000);
    },
    basetaginit(creditNo) {
      let _this = this;
      let params = {};
      const sdata = C10yUtil.SIGN.genSign(["company_base_tag", null]);
      params.extNonce = sdata.extNonce;
      params.rowkey = sdata.rowkey;
      params.time = sdata.time;
      params.id = creditNo;
      console.log("-----params--------->>>>>>", params);
      // this.lyId
      basetagapi(params).then((res) => {
        // if(res.data != null){
        // _this.enterpriselist = res.data
        Vue.set(_this.enterpriselist, "basetaglist", res.data ?? ["9"]);
        // this.basetaglist = res.data
        // _this.enterpriselist = res.data
        console.log("_this_this_this_this", _this.enterpriselist);

        // }
      });
    },
    handleds_ly_swly_list(name) {
      const now = new Date();
const year = now.getFullYear();
let month = now.getMonth() + 1; // 月份从0开始，需要加1
let day = now.getDate();
if (month >= 1 && month <= 9) {
          month = "0" + month;
        }
      if (day >= 0 && day <= 9) {
        day = "0" + day;
  }

console.log(year, month, day);
      let _this = this;
      let params = {
        formData: {
          name: `%${name}%`,
          pageNumber: 1,
          endDate:`${year}-${month}-${day}`
        },
      };
      ds_ly_swly_list(params).then((res) => {

        console.log("搜索接口返回数据===========》", res);
        let pointList = res.data.content;
        _this.enterpriselistLY = [];
        pointList.forEach((items) => {
          let pI = items.geocenter84
            .replace("POINT(", "")
            .replace(")", "")
            .split(" ");
          Vue.set(items, "polygoncenterdata", pI[0] + "," + pI[1]),
            _this.enterpriselistLY.push({
              ...items,
            });
          Vue.set(items, "point", { lng: pI[0], lat: pI[1] });
          Vue.set(items, "title", items.name);
          // items.point={lng:pI[0],lat:pI[1]}
        });
		let list = res.data.content.map((v) => {

		  return {
		    ...v,
		    title: v.name,
		    type: "buildiing",
		    centerPoint: gcoord.transform(
		      v.geocenter84
		        .replace("POINT(", "")
		        .replace(")", "")
		        .split(" ")
		        .map((v) => +v),
		      gcoord.WGS84,
		      gcoord.BD09
		    ),
		    polygonFormat: v.geom84
		      .replace("POLYGON((", "")
		      .replace("))", "")
		      .split(",")
		      .map((v) => {
		        return gcoord.transform(
		          v.split(" ").map((v) => +v),
		          gcoord.WGS84,
		          gcoord.BD09
		        );
		      }),
		  };
		});
		 _this.enterpriselistLY = list
        console.log("搜索接口返回数据==1---------->", _this.enterpriselistLY);
        _this.resultsApiList = pointList;
      });
    },
    // 获取企业搜索的参数数据
    handleChildSearchs() {
      console.log("444444444444444444444", this.lyId);
      //TODO 把参数获取到后去搜索table列表接口
      let queryParams = {
        formData: {
          lyId: this.lyId,
          pageNumber: this.pageNumberQY,
          pageSize: 10,
        },
        // polygon: this.polygonString,
      };
      this.enterpriselist = [];
      let _this = this;
      company_base_listTab(queryParams).then((res) => {
        // console.log("企业数据===========》", res);

        _this.QYINDEX++;
        _this.enterpriselist = res?.data?.content ?? [];

      });
    },
    getTime(item) {
      console.log("eeeeeeeee", item);
      let _this = this;
      _this.TabId = item;
      let items = _this.list[item];
      console.log("itemitemitemitemitemitemitemitemitem", item);
      console.log("itemsitemsitemsitemsitemsitems", items);
      _this.getKM = _this.marks[items.id];
      console.log("wwwwwwwwwwwwwwwwwwwwwwwww", _this.getKM);
      _this.successLY = 0;
      _this.KMKET++;
      // _this.handleChecked(true);
      _this.setKMMap(items);
    },
    setPageNum(num) {
      this.pageNumber = num;
      this.handleChildSearchs(this.ChildSearchsV);
    },
    // 获取楼宇
    handlely_shp_geo_polygon_company_list() {
      this.loadingLY = true;
      let queryParams = {
        formData: { polygon: this.polygonString },
        // pageNumber: this.pageNumber,
        // pageSize: 20,
      };
      let _this = this;
      ly_shp_geo_polygon_company_list(queryParams).then((res) => {
		  let list = res.data.content.map((v) => {

		    return {
		      ...v,
		      title: v.name,
		      type: "buildiing",
		      centerPoint: gcoord.transform(
		        v.geocenter84
		          .replace("POINT(", "")
		          .replace(")", "")
		          .split(" ")
		          .map((v) => +v),
		        gcoord.WGS84,
		        gcoord.BD09
		      ),
		      polygonFormat: v.geom84
		        .replace("POLYGON((", "")
		        .replace("))", "")
		        .split(",")
		        .map((v) => {
		          return gcoord.transform(
		            v.split(" ").map((v) => +v),
		            gcoord.WGS84,
		            gcoord.BD09
		          );
		        }),
		    };
		  });
		  console.log('centerPoint',list)
        console.log("楼宇数据===========》", res?.data?.content);
        //  _this.map.clearOverlays();
        _this.successLY = 1;
        // _this.enterpriselistLY2 = res?.data?.content;
		_this.enterpriselistLY2 = list;
        _this.totalLY = res?.data?.total;
        _this.loadingLY = false;
        if (res?.data?.content.length > 0  ) {
			for (var i = 0; i < list.length; i++) {
        _this.totalQY += list[i].comCount;
				if(list[i].name.indexOf(this.input4) >-1 || _this.input4 ){

					_this.mPoint = {
					  // lng: res?.data?.content[0].polygoncenterdata.split(",")[0],
					  // lat: res?.data?.content[0].polygoncenterdata.split(",")[1],
						lng: list[i]?.centerPoint[0],
						lat: list[i]?.centerPoint[1],
					};
					// window.setTimeout(() => {
					//   _this.map?.panTo(
					//     new BMap.Point(
					//     list[i]?.centerPoint[0],
					// 		list[i]?.centerPoint[1]
					//     ),
					//     11
					//   );
					// }, 2000);
					console.log('_this.mPoint',_this.mPoint)
					_this.handleChecked(true);
					_this.setMarker();
					// _this.mapPointsList = list
					_this.miaobian();
				}

			}

        }

        // _this.handleChecked(true);

        if (_this.search == true) {
          _this.isChecked = true;
        } else {
        }
        // _this.mPoint = _this.convertGoogleToBaidu(   );
      });
    },

    zoomIn() {
      const map = this.map;
      if (map) {
        map.zoomIn();
      }
    },
    zoomOut() {
      const map = this.map;
      if (map) {
         if( map.getZoom()>10){
             map.zoomOut();
                  }

        // this.zoomOutByLevel(5)
      }
    },
    zoomOutByLevel(levels) {
  var currentZoom = map.getZoom(); // 获取当前的缩放级别
  var newZoom = currentZoom - levels; // 计算新的缩放级别
  newZoom = Math.max(Math.min(newZoom, 19), 3); // 确保新的缩放级别在允许的范围内
  map.setZoom(newZoom); // 设置新的缩放级别
},
    setKMMap(v) {
		console.log('setKMMapv',v)
      const map = this.map;
      // this.getKM = v.label

      this.getKM = this.marks[v.id];

      console.log("-----vvvvv--->", this.getKM);
      if (v.scale <= 2) {
        map.zoomOut();
      } else {
        map.zoomIn();
      }
      this.setKM(v);
    },

    handleChangeIds(val) {
      this.changeId = true;
    },
  },
};
</script>

<style scoped lang="scss">
@import url("./css/map.scss");

.searchStyleP {
  position: relative;
}
.dragSearch {
  position: absolute;
  top: 25px;
  right: 40px;
  z-index: 8;
}
.searchStyleAbsolute {
  background-color: #fff;
  width: 100%;
  position: absolute;
  top: 53px;
  z-index: 999;
  display: flex;
  flex-direction: column;
  box-shadow: 0px 2px 6px 0px rgba(7, 28, 69, 0.3);
  padding: 10px 0;
  cursor: pointer;
  max-height: 500px;
  overflow-y: scroll;
}
.searchStyleAbsolute-item {
  padding: 8px 10px;
  font-size: 14px;
  display: flex;
  flex-direction: row;
  align-items: center;
}
.searchStyle {
  width: 452px;
  height: 53px;
  background-color: #fff;
  box-shadow: 0px 2px 6px 0px rgba(7, 28, 69, 0.3);
  border-radius: 0px 0px 0px 0px;
  border-radius: 4px;
  display: flex;
  flex-direction: row;
  align-items: center;
}
::v-deep .searchStyle .el-input__inner {
  border: 0 !important;
}
.searchBtn {
  height: 53px;
}
.slideStyle {
  width: 452px;
  position: absolute;
  top: 35px;
  z-index: 8;
  background-color: #fff;
  height: 75px;
  border-radius: 4px;
  margin-top: 25px;
  overflow: hidden;
  display: flex;
  flex-direction: column;
  justify-content: center;
}
.huakuai {
  width: 429px;
  padding: 5px;
  background: #f7f8fb;
  margin: 0 auto;
  border-radius: 4px;
  display: flex;
  flex-direction: row;
  justify-content: space-between;
  align-items: center;
}
.huakuai-right {
  width: 70%;
}
.huakuai-right-bottom {
  display: flex;
  flex-direction: row;
  align-items: center;
  justify-content: space-between;
}
.lab {
  font-family: PingFang SC, PingFang SC;
  font-weight: 400;
  font-size: 14px;
  color: #222222;
  cursor: pointer;
}
.activeLab {
  font-family: PingFang SC, PingFang SC;
  font-weight: 400;
  font-size: 15px;
  color: #3360d7;
  cursor: pointer;
}
// .drag {
//   position: absolute;
//   top: 25px;
//   left: 40px;
//   z-index: 8;
//   background-color: #fff;
//   box-shadow: 0px 2px 6px 0px rgba(7, 28, 69, 0.3);
//   border-radius: 4px;
//   overflow: hidden;
// }

// .drag-item {
//   width: 74px;
//   height: 78px;
//   display: flex;
//   flex-direction: column;
//   justify-content: center;
//   align-items: center;
//   cursor: pointer;
// }
// .active {
//   background-color: #0071df;
// }
// .color1 {
//   color: #222;
// }
// .color2 {
//   color: #fff;
// }
.pianqu1 {
  font-family: Microsoft YaHei, Microsoft YaHei;
  font-weight: bold;
  font-size: 14px;
  color: #616266;
}
.pianqu1:hover {
  background: #f6f7fa;
}
.pianqu {
  font-family: Microsoft YaHei, Microsoft YaHei;
  font-weight: 400;
  font-size: 14px;
  color: #999999;
  margin-left: 15px;
}
.w18 {
  width: 18px;
  height: 18px;
  display: inline-block;
  margin-right: 5px;
}
#baidumap {
  height: 100%;
}
</style>
